//package com.changgou.web.gateway.filter;
//
//import com.changgou.web.gateway.service.AuthService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.gateway.filter.GatewayFilterChain;
//import org.springframework.cloud.gateway.filter.GlobalFilter;
//import org.springframework.core.Ordered;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpRequest;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.util.StringUtils;
//import org.springframework.web.server.ServerWebExchange;
//import reactor.core.publisher.Mono;
//
//@Component
//public class AuthFilter1 implements GlobalFilter, Ordered {
//
//    @Autowired
//    private AuthService authService;
//
//    @Override
//    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//
//        System.out.println("执行我的filter：验证cookie中是否有jti，redis中是否有jwt");
//
//
//        ServerHttpRequest request = exchange.getRequest();
//        ServerHttpResponse response = exchange.getResponse();
//        String path = request.getURI().getPath();
//        // 如果是登录路径，则放行
//        if (path.equals("/api/oauth/login") || !UrlFilter.hasAuthorize(path)) {
//            return chain.filter(exchange);
//        }
//
//
//        // 从cookie中拿jti
//        String jti = authService.getJtiFromCookie(request);
//        if (StringUtils.isEmpty(jti)) {
//            // 拒绝访问
//            response.setStatusCode(HttpStatus.UNAUTHORIZED);
//            return response.setComplete();
//        }
//
//        // 从redis拿jwt
//        String jwt = authService.getJwtFromRedis(jti);
//        if (StringUtils.isEmpty(jwt)) {
//            response.setStatusCode(HttpStatus.UNAUTHORIZED);
//            return response.setComplete();
//        }
//
//
//        // 对请求对象增强，让他携带令牌
//        request.mutate().header("Authorization", "Bearer " + jwt);
//        return chain.filter(exchange);
//
//    }
//
//    @Override
//    public int getOrder() {
//        return 0;
//    }
//}
